package cn.yunhe.server;

import cn.yunhe.dao.IReplyDao;
import cn.yunhe.entity.Reply;
import cn.yunhe.entity.Topic;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ReplyServer {
    SqlSession session = SqlSessionFactoryUtil.getSqlSession(); //获取SQLSession对象
    IReplyDao mreplyDao = session.getMapper(IReplyDao.class); //通过映射获取replydao对象


    /**
     * 回复主贴方法
     * @param reply 回帖对象
     * @return
     */
    public boolean replyTopic(Reply reply){

        boolean flag =  mreplyDao.replyTopic(reply);
        if (flag){
            session.commit();
            return flag;
        }else {
            return false;
        }
    }


    /**
     * 获取主贴对应的回帖
     * @param topic 主贴对象
     * @return 回帖对象集合
     */
    public List<Reply> getReplyByTopic(Topic topic){
       return mreplyDao.getReplyByTopic(topic);
    }

}
